const http = require("http");
const url = require("url")
// 引入事件类
const EventEmiter = require("events");
// 实例化事件类
const routeEvent = new EventEmiter();
// 引入routes路由
let routes = require("./routes");
routes(routeEvent); // 实参

let server = http.createServer((req, res) => {
  res.setHeader("content-type", "text/html;charset=ut-8");
  // 把req.url里真正的地址提取出来
  // 使 /index?name=123  ---> /index
  let urlObj = url.parse(req.url, true);
  // console.log(urlObj);
  let pathname = urlObj.pathname;
  routeEvent.emit(pathname, req, res); //实参
})

server.listen(8060);